package com.example.rg1movieinfoapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.rg1movieinfoapp.image.SmartImageView;

import java.util.List;

public class MovieAdapter extends ArrayAdapter<Movie>
{
    private int listItemID;

    public MovieAdapter(@NonNull Context context, int resource, @NonNull List<Movie> objects) {
        super(context, resource, objects);
        listItemID=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Movie movie=getItem(position);
        View view= LayoutInflater.from(getContext()).inflate(listItemID,null);
        SmartImageView imageView=view.findViewById(R.id.imageView);
        TextView textView=view.findViewById(R.id.textView);
        imageView.setImageUrl("http://sdchengjie.uicp.net/drawable/"+movie.getIcon());
        textView.setText(movie.getTitle());
        return view;

    }
}
